var PlainTextMsgSender = (function(){
    
    var _PlainTextMsgSender = (function(){}).extend(MsgSender);
    
    _PlainTextMsgSender.prototype.send = function(cb){
        var _this = this;
        var chatGroupEntity = page.chatGroupStore.getItem(_this.chatGroupID);
        var content = _this.content.trimEmptyTags().safeString(); //msg object中的content是转义后的.
        
        var textData = {                        
            content : content,
            contentType : "text",
            createTime : Date.now(),                
            //id : msg['id'],
            seq : 0,
            teid : _this.chatGroupID                        
        };            
        if(chatGroupEntity.perm.rloc && page.position){
            textData['la'] = page.position.coords.latitude;
            textData['lo'] = page.position.coords.longitude;
        }
        //呈现PlainTextMsg.
        var textMsg = (new ChatTextMsg(textData, 'right')).render(_this.chatPanel.chatView);
        
        textMsg.markSending();
        
        var flag = false;
        if(textMsg.canShowReaders()){
            flag = true;
            textMsg.disableShowReaders();
        }
        
        page.biz.sendPlainMsg(this.chatGroupID, this.content).done(ujs.hr(function(msg){            
            textMsg.clearSending();
            if(_this.chatPanel.chatGroupEntity.type == 'singlechat'){
                textMsg.setUnread();
            }
            //将TextMsg添加到本地缓存.
            page.chatMsgStore.addItem({
                local : true,
                teid : _this.chatGroupID,
                seq : msg['seq'],
                createTime : msg['time'],
                contentType : MsgType.TEXT,
                from : 'web',
                id : msg['id'],
                content : content,      
                user : _this.user
            });  
            textMsg.updateSeq(msg['seq']).updateMsgTime(msg['time']);
            textMsg.adjustPos(msg['seq']).chatView.refreshReadCount();
            if(flag){
                textMsg.enableShowReaders();
            }          
            cb && cb(msg);                
        }, function(){
            textMsg.markFailed();
            textMsg.$retryBtn.click(function(){
                textMsg.hide();
                _this.send(function(){
                    _this.chatPanel.chatView.$wrapper.scrollToEnd();
                });
                return false;
            });
        })).fail(function(){
            textMsg.markFailed();
            textMsg.$retryBtn.click(function(){
                textMsg.hide();
                _this.send(function(){
                    _this.chatPanel.chatView.$wrapper.scrollToEnd();
                });
                return false;
            });
        });        
    };
    
    return _PlainTextMsgSender;
})();